package com.project.controller;

import com.project.dto.MaterialDTO;
import com.project.dto.MaterialPageQueryDTO;
import com.project.result.PageResult;
import com.project.result.Result;
import com.project.service.MaterialsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping
public class MaterialsController {
    @Autowired
    private MaterialsService materialsService;

    /**
     * 新增材料
     */
    @PostMapping
    public Result create(@RequestBody MaterialDTO dto) {
        materialsService.createMaterials(dto);
        return Result.success();

    }

    /**
     * 修改分类
     */
    @PutMapping
    public Result update(@RequestBody MaterialDTO dto) {
        materialsService.updateMaterials(dto);
        return Result.success();
    }

    /**
     * 修改状态
     */
    @PutMapping("/status/{status}")
    public Result updateStatus(@PathVariable("status") Integer status,Integer id) {
        materialsService.updateStatus(status,id);
        return Result.success();
    }

    /**
     * 删除材料
     */
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
       materialsService.deleteMaterials(id);
        return Result.success();
    }
    /**
     * 批量删除材料
     */
    @DeleteMapping
    public Result deleteIds(@RequestParam List<Integer> ids){

        materialsService.deleteBatch(ids);
        return Result.success();
    }


    /**
     * 材料信息分页查询（XML + PageHelper 实现）
     */
    @GetMapping("/page")
    public Result<PageResult> page(MaterialPageQueryDTO queryDTO) {
        PageResult page=materialsService.pageQuery(queryDTO);
//
        return Result.success(page);
    }

}
